package hexapawn.game;

import java.util.LinkedList;
import java.util.List;

/**
 * class TopPlayer - The Player object that starts at the top of the board.
 * 					 All the pieces may only move downwards. Downwards is
 * 					 towards bigger rows.
 * 
 * @author ChaoSXDemon
 *
 */
public class TopPlayer extends Player{

	public TopPlayer(Board _board) {
		super(_board, Player.PLAYER_1);
	}
	
	protected void removeTarget(Cell target){
		Player other = board.getBottomPlayer();
		other.getPieces().remove(target.getPiece());
	}

	@Override
	public List<Cell> getPossibleMoves(Cell _from){
		List<Cell> possibleMoves = new LinkedList<Cell>();
		from = _from;
		int row = from.getRow();
		int col = from.getColumn();
		if(row+1 < board.getRow()){
			Cell below, belowLeft, belowRight;
			below = board.getCellBelow(from);
			if(!below.hasPiece()) possibleMoves.add(below);
			if(col-1 >= 0){
				belowLeft = board.getCellBelowLeft(from);
				if(belowLeft.hasPiece())
					if(belowLeft.getPiece().getOwner() == PLAYER_2) possibleMoves.add(belowLeft);
			}
			if(col+1 < board.getColumn()){
				belowRight = board.getCellBelowRight(from);
				if(belowRight.hasPiece())
					if(belowRight.getPiece().getOwner() == PLAYER_2) possibleMoves.add(belowRight);
			}
		}
		if(possibleMoves.size() == 0) from = null;
		return possibleMoves;
	}

}
